/*
 * admin.c
 * 管理员程序
 */

#include "admin.h"

/*文件及文件指针定义*/
//------------------------------------
FILE *f_user_info, *f_lottery_info, *f_lottery_man, *f_prize_pool;
char* user_info="data/user_info.txt";
char* lottery_info="data/lottery_info.txt";
char* lottery_man="data/lottery_man.txt";
char* prize_pool="data/prize_pool.txt";
//------------------------------------

/*全局变量声明*/
//------------------------------------
int  QIHAO, perPrice_lottery, STATE;
//------------------------------------

/*主函数*/
//------------------------------------
int main(int argc, char **argv)
{
	int ifempty=1; //查看如果文件没有内容
	f_lottery_man=fopen(lottery_man,"r");
	if(!f_lottery_man){perror("");exit(1);}
	if(fscanf(f_lottery_man,"%d %d %d",\
				&QIHAO,&perPrice_lottery,&STATE)>0)
		ifempty=0; 
	if(ifempty){QIHAO=999,perPrice_lottery=10,STATE=1;}
	fclose(f_lottery_man);
	
	/*初始化head*/
	pNode list_arr[ARR_SIZE];
	int i=ARR_SIZE; enum _arr_list{_user_list, new_lottery_list, all_lottery_list};
	while(i--) 
	{
		list_arr[i] = (pNode)calloc(1,sizeof(xNode));
		if(!list_arr[i]){perror("head error");exit(1);}
	}
	/*加载用户信息*/
	load_users(list_arr[_user_list]);
	load_lottery(list_arr[new_lottery_list],1);
	load_lottery(list_arr[all_lottery_list],0);
	
	/*初始化选项*/
	enum MENU{_out, _issue_version, _show_users, _show_lotteries,_show_new_lotteries, _sort_users,_sort_lotteries, _pool_recharge, _sysout=99,_menu=11};
	/*进入界面操作*/
	menu();
	while(1){
	printf("请输入操作序号：");
	int choose=0; scanf("%d",&choose);
	switch(choose){
		case _out: free_list_arr(list_arr,ARR_SIZE);exit(0);
		break;
		case _sysout: free_list_arr(list_arr,ARR_SIZE);exit(3);
		break;
		case _menu: menu();
		break;
		case _sort_users: 
		sort(list_arr[_user_list], compare_balance);
		show_users(list_arr[_user_list]);
		break;
		case _sort_lotteries: 
		sort(list_arr[new_lottery_list], compare_prize_status);
		show_lottery(list_arr[new_lottery_list]);
		break;
		case _issue_version: issue_version();
		break;
		case _show_users: show_users(list_arr[_user_list]);
		break;
		case _show_lotteries: show_lottery(list_arr[all_lottery_list]);
		break;
		case _show_new_lotteries: show_lottery(list_arr[new_lottery_list]);
		break;
		case _pool_recharge: pool_recharge();
		break;
		
		default: printf("输入不合法!\n");break;
		}
	}
	return 0;
}
//------------------------------------

